<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <!--        type 0 学生 2 职工-->
        <span>{{ listType == 1 ? '已签收学生' : '未签收学生' }}明细</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <!--本体列表，数据 -->
        <div class="table-body">
          <div class="table-body-box">
            <el-table
              ref="multipleTable"
              :data="arryList"
              border
              :height="tableHeight"
              tooltip-effect="dark"
              style="width: 100%"
              header-cell-class-name="table-text-c"
              cell-class-name="table-text-c">
              <el-table-column
                prop="create_time"
                label="签名时间"
                :key="1"
                v-if="listType==1">
              </el-table-column>
              <el-table-column
                label="签名人"
                :key="2"
                v-if="listType==1">
                <template slot-scope="scope">
                  <span>
                  {{ `${scope.row.parents ? scope.row.parents.name : '--'}` }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column
                label="学生姓名"
                :key="3">
                <template slot-scope="scope">
                  <span v-if="listType==1">{{ scope.row.student ? scope.row.student.name : '--' }}</span>
                  <span v-else>{{ scope.row.name }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="学生班级"
                :key="4">
                <template slot-scope="scope">
                  {{ scope.row.classes ? scope.row.classes.class_name : '--' }}
                </template>
              </el-table-column>
              <el-table-column
                label="学生家长"
                :key="5"
                v-if="listType==2">
                <template slot-scope="scope">
                  <div class="parentsList" v-if="scope.row.parents.length!==0">
                    <!--                    <p v-for="(item,index) in scope.row.parents" :key="index" class="curpointLine">{{ item.name }}<span-->
                    <!--                        v-if="item.relation">({{ item.relation }}),{{-->
                    <!--                        item.mobile_phone ? item.mobile_phone : '&#45;&#45;'-->
                    <!--                      }}</span></p>-->
                    <p v-for="(item,index) in scope.row.parents" :key="index" class="curpointLine">{{ item.name }}<span
                      v-if="item.relation">({{ item.relation }}),<i v-if="item.mobile_phone" @click="$verifyCheking('phone', item.mobile_phone)">查看电话</i>
                      <i v-else>--</i></span></p>
                  </div>
                  <div v-else>
                    无数据
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                label="状态"
                :key="6"
                width="150"
                v-if="listType==2">
                <template slot-scope="scope">
                  <span class="c-danger">未签收</span>
                </template>
              </el-table-column>
              <el-table-column
                label="匹配状态"
                :key="7"
                v-if="listType==1">
                <template slot-scope="scope">
                  <span>已匹配</span>
                </template>
              </el-table-column>
              <el-table-column
                label="签名"
                width="100"
                :key="8"
                v-if="listType==1">
                <template slot-scope="scope">
                  <viewerModle type="1" :imgSrc="scope.row.pic?scope.row.pic:''"></viewerModle>
                </template>
              </el-table-column>
              <el-table-column
                label="打印"
                width="200"
                :key="9"
                v-if="listType==1">
                <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="checkStudent(scope.$index)">预览打印通知</el-button>
                  <el-button v-if="listType==1" plain type="danger" @click="handleDetel(scope.row.id)" size="mini">删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
            background
            :page-size="page.pagesize"
            :current-page="page.pageindex"
            layout="total, prev, pager, next"
            :total="page.total"
            @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
    <print :visible.sync="printvisible" :studentInfo="studentInfo" type="2"></print>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import {noticeUser, noticeUnread, noticeDelete} from '@/api/admin/notice'
import print from '@/components/dialog/print.vue'

export default {
  props: ['visible', 'noticeId', 'listType'], // listType 1 签收 2 未签收
  components: {print},
  data() {
    return {
      healthId: 0,
      dialogVisible: this.visible,
      arryList: [], // 数据列表
      printvisible: false,
      studentInfo: {},
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      tableHeight: 0,
      detailId: 0,
      detailVisible: false
    }
  },
  watch: {
    visible() {
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51 + 20 + 50 + 51)
        })
        this.InitFn()
      } else {
        this.arryList = [];
        this.page.pageindex = 1
        this.page.total = 0
      }
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 初始化
    async InitFn() {
      let option = {}
      option.p = this.page.pageindex
      option.id = this.noticeId
      if (this.listType === 1) {
        noticeUser(option).then(res => {
          if (!res.code) {
            for (let item of res.list.data) {
              item.create_time = item.create_time.split(' ')[0]
            }
            this.arryList = res.list.data
            this.page.total = res.list.total
          }
        })
      } else {
        noticeUnread(option).then(res => {
          if (!res.code) {
            this.arryList = res.list.data
            this.page.total = res.list.total
          }
        })
      }
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    checkStudent(index) {
      this.studentInfo = this.arryList[index]
      this.printvisible = true
    },
    handleDetel(id) {
      this.$confirm('确认删除该生签收记录,删除后家长可重新签收 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        noticeDelete({id: id}).then(res => {
          console.log(res)
          if (!res.code) {
            this.$message.success(res.msg)
            this.InitFn()
            this.$emit('InitFn')
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.breadcrumb-container {
  margin-bottom: 10px;
}

.parentsList p {
  background: #f8f8f8;
  margin-bottom: 5px;
}

.parentsList p:last-child {
  margin-bottom: 0;
}
</style>


